import 'package:flutter/material.dart';

class TabView extends StatefulWidget {
  final int checkedIndex;
  final ValueChanged<int> onChanged;

  const TabView({Key key, @required this.checkedIndex, this.onChanged})
      : super(key: key);

  @override
  _TabViewState createState() => _TabViewState();
}

class _TabViewState extends State<TabView> {
  int _checkedIndex;

  @override
  void initState() {
    _checkedIndex = widget.checkedIndex;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 50,
      color: Colors.white,
      child: Row(
        mainAxisSize: MainAxisSize.max,
        children: [
          Expanded(
            child: Container(
              alignment: Alignment.center,
              child: InkWell(
                child: Text(
                  '我发起的',
                  style: TextStyle(
                      color: _checkedIndex == 0
                          ? Theme.of(context).primaryColor
                          : Colors.black54,
                      fontSize: _checkedIndex == 0 ? 18 : 16),
                ),
                onTap: () {
                  setState(() {
                    _checkedIndex = 0;
                  });
                  if (widget.onChanged != null) {
                    widget.onChanged(_checkedIndex);
                  }
                },
              ),
            ),
          ),
          Expanded(
            child: Container(
              alignment: Alignment.center,
              child: InkWell(
                child: Text(
                  '我接受的',
                  style: TextStyle(
                      color: _checkedIndex == 1
                          ? Theme.of(context).primaryColor
                          : Colors.black54,
                      fontSize: _checkedIndex == 1 ? 18 : 16),
                ),
                onTap: () {
                  setState(() {
                    _checkedIndex = 1;
                  });
                  if (widget.onChanged != null) {
                    widget.onChanged(_checkedIndex);
                  }
                },
              ),
            ),
          ),
        ],
      ),
    );
  }
}
